﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DAL;
public partial class UserUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            databind();
        }

    }
    private void databind()
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        using (DataClassesDataContext lqDB = new DataClassesDataContext())
        {
            Users user = lqDB.Users.FirstOrDefault(u => u.ID == id);
            txtLoginnames.Text = user.LoginName;
            txtNames.Text = user.UserName;
            txtPsws.Text = user.PassWord;
            txtPhones.Text = user.Phone;
            cmdCommunitys.Text = user.Communities;
        }
    }
    protected void btnOK1_Click1(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        using (DataClassesDataContext lqDB = new DataClassesDataContext())
        {
            Users user = lqDB.Users.FirstOrDefault(u => u.ID == id);
            user.LoginName = txtLoginnames.Text;
            user.UserName = txtNames.Text;
            user.PassWord = txtPsws.Text;
            user.Phone = txtPhones.Text;
            user.Communities = cmdCommunitys.SelectedItem.Value.ToString();
            lqDB.SubmitChanges();
            Frame.Global.GlobalFunctions.AlertToUrl("修改成功！", "EditUser.aspx");
        }
    }
    protected void btnCancel1_Click(object sender, EventArgs e)
    {
        Response.Redirect("EditUser.aspx");
    }
}